package history

import (
	"fmt"
	"sync"
)

func call() {
	var data = make(chan int, 1000)
	var group = sync.WaitGroup{}
	group.Add(11)
	go func() {
		for i := 0; i < 1000; i++ {
			data <- i
		}
		close(data)
	}()
	for i := 0; i < 10; i++ {
		var idx = i
		go func(idx int) {
			defer group.Done()
			for {
				val, ok := <-data
				if !ok {
					return
				}
				fmt.Println("第", idx, "个协程访问，访问值为: ", val)
			}
		}(idx)
	}
	group.Wait()
}
